<?php
// TODO: move to the API

$r = false;

if(!empty($_GET['f']))
{
	list($key, $value) = each($_GET['f']);
	$value = $FILTER->ClearString($value);

	switch($key)
	{
		case 'name':
			$DB->sql = 'SELECT COUNT(*) AS q FROM meccano_fields WHERE alias = "'. $value .'"';
			$DB->DB_Query();
			if($DB->DB_GetResult() == 0) $r = true;
			break;
			
		case 'fset_name':
			$DB->sql = 'SHOW TABLES LIKE "meccano_'. $value .'"';
			$DB->DB_Query();
			if($DB->DB_GetRows() == 0) $r = true;
			break;
	}
}

echo json_encode($r);